<?php
$this->breadcrumbs = array(
    '权限管理',
);
?>
<div class="submenu">
    <div class="row">
        <div class="col-md-4">
            <?php
            $form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
                'id' => 'search-form',
                'type' => 'search',
                'method' => 'GET',
                'action' => $this->createUrl(Yii::app()->getController()->getAction()->id),
                'htmlOptions' => array('class' => 'navbar-search pull-left', 'style' => 'margin:0;width:100%;'),
            ));
            echo '<div class="input-group">';
            echo $form->textFieldRow($model, 'searchKey', array(
                'class' => 'form-control',
            ));
            echo '<div class="input-group-btn"><button class="btn btn-primary" style="" type="submit" name="yt0"><i class="fa fa-search"></i></button></div>';
            echo '</div>';
            $this->endWidget();
            ?>
        </div>
        <div class="col-md-8">
            <?php

            $this->widget('bootstrap.widgets.TbButton', array(
                'label' => '新增',
                'type' => 'success',
                'htmlOptions' => array('class' => 'pull-right btn-success', 'style' => 'width:100px'),
                'url' => $this->createUrl('create'),
            ));
            ?>
        </div>
    </div>
</div>
<div style="min-height:300px;">
    <?php
    $columns = array(
        array('name' => 'name', 'headerHtmlOptions' => array('style' => 'width:10%')),
        array('name' => 'pid', 'value' => array($this, 'colRevise'), 'headerHtmlOptions' => array('style' => 'width:10%')),
        array('name' => 'type', 'headerHtmlOptions' => array('style' => 'width:10%')),
        array('name' => 'authtype', 'headerHtmlOptions' => array('style' => 'width:10%')),
        array('name' => 'action', 'headerHtmlOptions' => array('style' => 'width:20%')),
        array('name' => 'remark', 'headerHtmlOptions' => array('style' => 'width:34%')),
        array('class' => 'CLinkColumn',
            'label' => '<i class="fa fa-pencil"></i>',
            'urlExpression' => 'Yii::app()->getController()->createUrl("update",array("id"=>$data->id,))',
            'linkHtmlOptions' => array('data-original-title' => '更新', 'rel' => "tooltip"),
            'headerHtmlOptions' => array('style' => 'width:3%'),
        ),
        array('class' => 'CLinkColumn',
            'label' => '<i class="fa fa-trash"></i>',
            'urlExpression' => 'Yii::app()->getController()->createUrl("delete",array("id"=>$data->id,))',
            'linkHtmlOptions' => array('class' => 'delete', 'data-original-title' => '删除', 'rel' => "tooltip"),
            'headerHtmlOptions' => array('style' => 'width:3%'),
        ),
    );
    $this->widget('bootstrap.widgets.TbGridView', array(
        'id' => 'permission-grid',
        'ajaxVar' => null,
        'type' => array('striped'),
        'dataProvider' => $model->searchByKey(),
        'columns' => $columns,
    ));
    ?>
</div>
<script type="text/javascript">
    $(function ($) {
        $(document).on('click', 'a.delete', function () {
            if (!confirm('确定删除?')) return false;
            var th = this;
            var afterDelete = function () {
            };
            $.fn.yiiGridView.update('permission-grid', {
                type: 'POST',
                url: $(this).attr('href'),
                ajaxUpdate: false,
                success: function (data) {
                    if (data == 'Success') {
                        $.fn.yiiGridView.update('permission-grid');
                    } else {
                        alert(data);
                    }
                    afterDelete(th, true, data);
                },
                error: function (XHR) {
                    return afterDelete(th, false, XHR);
                }
            });
            return false;
        });
    });
</script>